package com.deyuanyun.pic.ctrl.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.deyuanyun.pic.ctrl.domain.ExinspAcMiorData;
import com.deyuanyun.pic.ctrl.domain.ExinspAcMiorDataExample;
import com.deyuanyun.pic.ctrl.domain.ExinspCpPower;
import com.deyuanyun.pic.ctrl.domain.ExinspCpPowerExample;
import com.deyuanyun.pic.ctrl.domain.ExinspDcMiorData;
import com.deyuanyun.pic.ctrl.domain.ExinspDcMiorDataExample;
import com.deyuanyun.pic.ctrl.mapper.ExinspAcMiorDataMapper;
import com.deyuanyun.pic.ctrl.mapper.ExinspCpPowerMapper;
import com.deyuanyun.pic.ctrl.mapper.ExinspDcMiorDataMapper;
import com.deyuanyun.pic.ctrl.service.ExinspChartService;

@Service
public class ExinspChartServiceImpl implements ExinspChartService {

    
    private @Resource ExinspAcMiorDataMapper exinspAcMiorDataMapper;
    private @Resource ExinspDcMiorDataMapper exinspDcMiorDataMapper;
    private @Resource ExinspCpPowerMapper exinspCpPowerMapper;
    
    @Override
    public byte[] queryStrayCurrentDataAC(String monitorRecordId) {
        
        ExinspAcMiorDataExample example = new ExinspAcMiorDataExample();
        example.createCriteria().andMonitorRecordIdEqualTo(monitorRecordId);
        
        List<ExinspAcMiorData> list = exinspAcMiorDataMapper.selectByExampleWithBLOBs(example);
        if(list == null || list.isEmpty()){
            return null;
        }
        return list.get(0).getTimeAndVoltages();
    }

    @Override
    public byte[] queryStrayCurrentDataDC(String monitorRecordId) {
        ExinspDcMiorDataExample example = new ExinspDcMiorDataExample();
        example.createCriteria().andMonitorRecordIdEqualTo(monitorRecordId);
        
        List<ExinspDcMiorData> list = exinspDcMiorDataMapper.selectByExampleWithBLOBs(example);
        if(list == null || list.isEmpty()){
            return null;
        }
        return list.get(0).getTimeAndVoltages();
    }

    @Override
    public ExinspCpPower queryExinspCpPower(String exinspTaskId,String cppowerId) {
        
        ExinspCpPowerExample example = new ExinspCpPowerExample();
        example.createCriteria().andExinspTaskIdEqualTo(exinspTaskId).andCppowerIdEqualTo(cppowerId);
        List<ExinspCpPower> exinspCpPowerList = exinspCpPowerMapper.selectByExample(example);
        if(exinspCpPowerList == null || exinspCpPowerList.isEmpty()){
            return null;
        }
        return exinspCpPowerList.get(0);
    }

}
